import { Vector2, Vector3 } from "three";
import { KujialeModelType } from "./KujialeModelType";

export class KujialeParamModel {
  id: string;
  position: Vector3;
  rotate: Vector3;
  rotateDegree: Vector3;
  absPosition: Vector3;
  absRotation: Vector3;
  customSize?: Vector3;
  size?: Vector3;
  boxSize?: Vector3;
  subModels?: KujialeParamModel[];
  paramPlankPath?: KujialeParamPlankPath;
  paramLoftPath?:KujialeParamLoftPath;
  profile?: KujialeProfile;
  thickness?: number;
  modelName: string;
  parameters: KujialeParameter[];
  textureName: string;
  prodCatId: number;
  /**
     * 模型类型，用于区分参数化模型1、五金2、元件3、虚拟模型4、参数化组合模型5
     */
  modelTypeId: KujialeModelType;
  //@type:string;

  constructor() {
    this.id = "";
    this.modelName = "模型名称";
    this.position = new Vector3();
    this.rotate = new Vector3();
    this.rotateDegree = new Vector3();
    this.absPosition = new Vector3();
    this.absRotation = new Vector3();
    this.position = new Vector3();
    this.parameters = [];
    this.textureName = "";
    this.prodCatId = 0;
    this.modelTypeId = KujialeModelType.ParamModel;
    //this.@type = "";
  }

  getModelWidth(): number {
    return this.boxSize!.x;
    // var parameter = this.parameters.find((it) => it.name == "W");
    // if (parameter == undefined) {
    //   if(this.boxSize){
    //     return this.boxSize.x;
    //   }
    //   return 0;
    // }
    // return parseFloat(parameter.value as string);
  }
  getModelHeight(): number {
    return this.boxSize!.z;
    // var parameter = this.parameters.find((it) => it.name == "H");
    // if (parameter == undefined) {
    //   if(this.boxSize){
    //     return this.boxSize.z;
    //   }
    //   return 0;
    // }
    // return parseFloat(parameter.value as string);
  }
  getModelDepth(): number {
    return this.boxSize!.y;
    // var parameter = this.parameters.find((it) => it.name == "D");
    // if (parameter == undefined) {
    //   if(this.boxSize){
    //     return this.boxSize.y;
    //   }
    //   return 0;
    // }
    // return parseFloat(parameter.value as string);
  }
}

export interface KujialeParamPlankPath {
  path?: KujialePath;
  holes?: KujialePath[];
}

export class KujialeParamLoftPath {
  resultPoints: Vector2[];
  resultLines: KujialeResultLine[];
  close: boolean;

  constructor() {
    this.close = true;
    this.resultPoints = [];
    this.resultLines = [];
  }
}

export class KujialePath {
  resultPoints: Vector2[];
  resultLines: KujialeResultLine[];

  constructor() {
    this.resultPoints = [];
    this.resultLines = [];
  }
}

export interface KujialeResultLine {
  type: number;
  clockwise?: boolean;
  minorArc?: boolean;
  radius?: number;
}

export class KujialeParameter {
  value: string | number;
  ignored: boolean;
  visible: boolean;
  editable: boolean;
  displayName: string;
  name: string;

  constructor() {
    this.value = "";
    this.ignored = false;
    this.visible = true;
    this.editable = true;
    this.displayName = "变量名称";
    this.name = "变量代号";
  }
}

export interface KujialeProfile {
  prodCatId: number;
  brandGoodName: string;
  available: boolean;
  brandName: string;
  onSale: boolean;
  billOutput: boolean;
}
